package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.view.View;

public class TimelineAudioViewHolder extends TimelineViewHolder implements TimelineAudioView.OnClickAudioListener {

    public interface OnClickAudioListener {

        void onClickAudio(TimelineAudioViewHolder holder);

        void onLongClickAudio(TimelineAudioViewHolder holder);

    }

    private TimelineAudioView mAudio;

    private OnClickAudioListener mOnClickAudioListener;

    public TimelineAudioViewHolder(Context context, View itemView) {
        super(context, itemView);
        mAudio = new TimelineAudioView(context);
        mAudio.setOnClickAudioListener(this);
        getContent().addView(mAudio);
    }

    public void setLength(int length) {
        mAudio.setLength(length);
    }

    public void play() {
        mAudio.play();
    }

    public void stop() {
        mAudio.stop();
    }

    public void ready() {
        mAudio.ready();
    }

    public void notReady() {
        mAudio.notReady();
    }

    public void setOnClickAudioListener(OnClickAudioListener listener) {
        mOnClickAudioListener = listener;
    }

    @Override
    public void onClickAudio() {
        if (mOnClickAudioListener == null) {
            return;
        }
        mOnClickAudioListener.onClickAudio(this);
    }

    @Override
    public void onLongClickAudio() {
        if (mOnClickAudioListener == null) {
            return;
        }
        mOnClickAudioListener.onLongClickAudio(this);
    }
}
